<!-- 绩效-基础设置-其他考核模板 -->
<template>
  <ContentCard>
    <template #header>
      <pageHeaderNew
        :title="title"
        :breadCrumb="breadCrumb"
        showBack
      ></pageHeaderNew>
    </template>
    <ConditionBox :margin-bottom="20">
      <template #left> </template>
      <template #right>
        <a-button type="primary" @click="add">新增模板</a-button>
      </template>
    </ConditionBox>
    <TableTurn :tableData="getPerformanceTemplate" ref="tableRef">
      <a-table-column dataIndex="" title="序号">
        <template #cell="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
      </a-table-column>
      <a-table-column
        dataIndex="name"
        title="其他考核模板名称"
      ></a-table-column>
      <a-table-column dataIndex="cycleType" title="考核周期"></a-table-column>
      <a-table-column
        dataIndex="performanceAssessmentTemplateRange"
        title="适用范围"
      ></a-table-column>
      <a-table-column dataIndex="" title="创建人"></a-table-column>
      <a-table-column dataIndex="" title="创建时间"></a-table-column>
      <a-table-column dataIndex="" title="启用状态">
        <template #cell="{ record }">
          <StatusTag
            :enable="record.status"
            :lable="record.status === 1 ? '启用' : '禁用'"
          />
        </template>
      </a-table-column>
      <a-table-column
        :width="120"
        data-index=""
        title="操作"
        fixed="right"
        align="center"
      >
        <template #cell="{ record }">
          <a-tooltip content="编辑">
            <IconFont
              type="icon-edit"
              :size="26"
              :style="{
                marginRight: '10px',
                cursor: 'pointer'
              }"
              @click="edit(record.id)"
            />
          </a-tooltip>
          <a-tooltip content="删除" position="left">
            <a-popconfirm content="是否确认删除该条数据?" @ok="del(record.id)">
              <icon-font
                type="icon-delete"
                :size="26"
                :style="{
                  cursor: 'pointer',
                  marginRight: '10px'
                }"
              />
            </a-popconfirm>
          </a-tooltip>
        </template>
      </a-table-column>
    </TableTurn>
  </ContentCard>
  <AddPerformanceTemplate
    v-model:visible="templateVisible"
    :data="templateDate"
    @save="save"
  >
  </AddPerformanceTemplate>
</template>

<script lang="ts" setup>
import {
  DelPerformanceAppraisalTemplate,
  GetPerformanceAppraisalTemplate,
  GetPerformanceAppraisalTemplateDetails,
  PostPerformanceAppraisalTemplate,
  PutPerformanceAppraisalTemplate
} from '@/apis/management/performance/baseSetting/template';
import AddPerformanceTemplate from '../PerformanceTemplate/compenents/AddPerformanceTemplateModal.vue';
import { PerformanceAppraisal } from '@/apis/management/performance/baseSetting/template/type';
import TableTurn, { paramsType } from '@/components/TableTurn/index.vue';

const router = useRouter();
const title = '其他考核模板';
const tableRef = ref();

const breadCrumb: string[] = ['人事', '基础设置', '考核模板库', '其他考核模板'];
/**
 * 获取其他考核模板列表
 */
const getPerformanceTemplate = async (params: paramsType) => {
  try {
    const res = await GetPerformanceAppraisalTemplate({
      templateType: 6
    });
    return Promise.resolve(res);
  } catch (error: unknown) {
    console.log(error);
  }
};
const templateVisible = ref(false);
const templateDate = ref<PerformanceAppraisal>({ templateType: 6 });
const add = async () => {
  templateDate.value = { templateType: 6 };
  templateVisible.value = true;
};
const edit = async (id: number) => {
  templateDate.value = await GetPerformanceAppraisalTemplateDetails({ id });
  const { cycleStart, cycleEnd } = templateDate.value;
  if (cycleStart) {
    let bginDate = new Date(cycleStart);
    let endDate = new Date(cycleEnd);
    templateDate.value.cycleStart = bginDate;
    templateDate.value.cycleEnd = endDate;
  }

  templateVisible.value = true;
};
const del = async (id: number) => {
  await DelPerformanceAppraisalTemplate({ ids: [id] });
};
const save = async (data: PerformanceAppraisal) => {
  if (data.id) {
    await PutPerformanceAppraisalTemplate(data);
  } else {
    await PostPerformanceAppraisalTemplate(data);
  }
};
</script>

<style scoped lang="less"></style>
